var stock;

function saveEntity(formId){
	var formToSubmit = $("#"+formId).formSerialize();
	var actionURL = $("#"+formId).attr("action");
	$.post(actionURL,formToSubmit,function(data){
		$("#contentDiv").empty().html(data);
	});
}
function addItemPage()
{
	$.post('addItem.htm',{},function(data){
			$("#contentDiv").empty().html(data);
		},"html");			
}
function searchItem()
{
	$.post('searchItem.htm',{},function(data){
		$("#contentDiv").empty().html(data);
	},"html");				
}
function searchItemTransaction()
{
	$.post('searchItemTransaction.htm',{},function(data){
		$("#contentDiv").empty().html(data);
	},"html");	
}
function itemTransaction()
{
	$.post('itemTransaction.htm',{},function(data){
		$("#contentDiv").empty().html(data);
	},"html");		
}
function getAvailableStock()
{
	$.post('itemFilter.htm',{},function(data){
		$("#contentDiv").empty().html(data);
	},"html");
}
function generatePurchaseorder()
{
	$.post('generatePurchaseorder.htm',{},function(data){
		$("#contentDiv").empty().html(data);
	},"html");
}
function createItemAutocomplete(inputBoxId){
	$("#"+inputBoxId).autocomplete({
		source: "/",
		minLength: 2,
		close: function(event,ui){
			checkStock("itemTransaction");
		},
			
		search : function(event,ui){
			var sourceURL = "getItemList.htm";
			$("#"+inputBoxId).autocomplete("option" , "source" , sourceURL);
			return true;
			}
	});
}
function checkStock(formId)
{
	var formdata = $("#"+formId).formSerialize();
//	var sourceURL = contextRoot	+ "getTagList/" + tagType +".htm";
	$.post("checkStock.htm",formdata,function(data){
		stock = data;		
		$("#availableStock").empty().html("Available Item Stock is "+data);
			},"html");
}
function checkOperation()
{
	var operationType = $('input:radio[name=opertionType]:checked').val();
	if(stock!=0)
	{
		$("#itemCount").attr("readonly","");
	}
	else if(operationType == 'Purchase' ||operationType == 'Return')
	{
		$("#itemCount").attr("readonly","");
	}
	else
	{	$("#itemCount").val("0");
		$("#itemCount").attr("readonly","readonly");
	}
}
function showJSP(responseText)  { 
	 
	
	$("#contentDiv").empty().html(responseText);
	

}